<template>
  <div class="qrcode-generator">
    <div>
      <label for="tvId">TV ID:</label>
      <input v-model="tvId" id="tvId" type="text" />
    </div>
    <div>
      <label for="endTime">End Time:</label>
      <input v-model="endTime" id="endTime" type="datetime-local" />
    </div>
    <button @click="generateQRCode">Generate QR Code</button>
    <div v-if="qrCodeDataUrl">
      <img :src="qrCodeDataUrl" alt="QR Code" />
    </div>
  </div>
</template>

<script>
import QRCode from 'qrcode'

export default {
  data() {
    return {
      tvId: '',
      endTime: '',
      qrCodeDataUrl: null
    }
  },
  methods: {
    generateQRCode() {
      const url = `${window.location.origin}/sign-in?tvId=${this.tvId}&endTime=${this.endTime}`
      QRCode.toDataURL(url)
        .then(dataUrl => {
          this.qrCodeDataUrl = dataUrl
        })
        .catch(err => {
          console.error(err)
        })
    }
  }
}
</script>

<style scoped>
.qrcode-generator {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.qrcode-generator div {
  margin-bottom: 10px;
}
</style>
